#include "btn_Impl.h"
#include "btnManager.h"
#include "ttMsgMap.h"
#include "ttCalcObjMgr.h"


SETSHAPE(buildPoint, 0, 0, 100, 50)
SETSHAPE(buildAndPoint, 101, 0, 100, 50)
SETSHAPE(buildOrPoint, 202, 0, 100, 50)
SETSHAPE(buildNotPoint, 303, 0, 100, 50)
SETSHAPE(drag, 404, 0, 100, 50)
SETSHAPE(link, 505, 0, 100, 50)
SETSHAPE(delPoint, 606, 0, 100, 50)
SETSHAPE(setVal, 707, 0, 100, 50)
SETSHAPE(run, 808, 0, 100, 50)

int
buildPoint::OnButtonClick()
{
	ttMsgMap::Get()->m_msglpvar.flagfalse();
	ttMsgMap::Get()->m_msglpvar.m_bBuilding = true;
	SetFocus(this->getContainer());
	return 0;
}

int
buildAndPoint::OnButtonClick()
{
	ttMsgMap::Get()->m_msglpvar.flagfalse();
	ttMsgMap::Get()->m_msglpvar.m_bBuildingAnd = true;
	SetFocus(this->getContainer());
	return 0;
}

int
buildOrPoint::OnButtonClick()
{
	ttMsgMap::Get()->m_msglpvar.flagfalse();
	ttMsgMap::Get()->m_msglpvar.m_bBuildingOr = true;
	SetFocus(this->getContainer());
	return 0;
}

int
buildNotPoint::OnButtonClick()
{
	ttMsgMap::Get()->m_msglpvar.flagfalse();
	ttMsgMap::Get()->m_msglpvar.m_bBuildingNot = true;
	SetFocus(this->getContainer());
	return 0;
}

int
drag::OnButtonClick()
{
	ttMsgMap::Get()->m_msglpvar.flagfalse();
	ttMsgMap::Get()->m_msglpvar.m_bDragging = true;
	SetFocus(this->getContainer());
	return 0;
}

int
link::OnButtonClick()
{
	ttMsgMap::Get()->m_msglpvar.flagfalse();
	ttMsgMap::Get()->m_msglpvar.m_bLinking = true;
	SetFocus(this->getContainer());
	return 0;
}

int
delPoint::OnButtonClick()
{
	ttMsgMap::Get()->m_msglpvar.flagfalse();
	ttMsgMap::Get()->m_msglpvar.m_bDeleting = true;
	SetFocus(this->getContainer());
	return 0;
}

int
setVal::OnButtonClick()
{
	ttMsgMap::Get()->m_msglpvar.flagfalse();
	ttMsgMap::Get()->m_msglpvar.m_bSetVal = true;
	SetFocus(this->getContainer());
	return 0;
}

int
run::OnButtonClick()
{
	SetFocus(this->getContainer());
	for (int i = 0; i < ttCalcObjMgr::Get()->length(); ++ i){
		ttPoint *pttp = (ttPoint*)ttCalcObjMgr::Get()->getObj(i);
		if (pttp->isEnd()){
			pttp->calc(0);
		}
	}
	return 0;
}